package main

import (
	"blogger/global"
	blogger "blogger/http"
	"fmt"
	"github.com/gin-contrib/sessions"
	"github.com/gin-contrib/sessions/cookie"
	"github.com/gin-gonic/gin"
)

func init() {
	// 初始化配置文件
	global.InitViper()
	// 初始化数据库
	global.InitMysql()

}

func main() {

	r := gin.Default()
	store := cookie.NewStore([]byte("secret"))
	// 使用session
	r.Use(sessions.Sessions("blogger", store))

	r.LoadHTMLGlob("template/*")
	r.Static("/static/", "./static")
	// 将样式文件制定url
	r.StaticFile("/editormd/lib/codemirror/codemirror.min.css", "./static/editormd/lib/codemirror/codemirror.min.css")
	// 设定前端路由组
	indexGroup := r.Group("")
	indexGroup.Use(Logger())
	blogger.RegisterRoutes(indexGroup)


	r.Run()
}

func Logger() gin.HandlerFunc {
	return func(c *gin.Context) {
		fmt.Println("我是请求之前", c.FullPath())
		c.Next()
		fmt.Println("我是请求之后", c.FullPath())
	}
}
